package com.newtype.meeting.client.widget.backend;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormButtonBinding;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.newtype.meeting.client.AppEvents;
import com.newtype.meeting.client.model.Title;

public class TitleAddWindow extends Window {

	public TitleAddWindow() {
		setHeading("新增");
		setWidth(350);
		setAutoHeight(true);
		setModal(true);
		setButtonAlign(HorizontalAlignment.CENTER);

		final FormPanel form = new FormPanel();
		form.setHeaderVisible(false);

		final SimpleComboBox<Integer> degree = new SimpleComboBox<Integer>();
		degree.setFieldLabel("职级");
		degree.setName("degree");
		degree.setTriggerAction(TriggerAction.ALL);
		degree.setEditable(false);
		for (int i = 0; i <= 50; i++) {
			degree.add(i);
		}
		degree.setSimpleValue(0);
		form.add(degree);

		final TextField<String> caption = new TextField<String>();
		caption.setFieldLabel("职称");
		caption.setName("titleCaption");
		caption.setAllowBlank(false);
		caption.getMessages().setBlankText("此栏位不可为空");
		form.add(caption);

		Button btnSend = new Button("送出");
		addButton(btnSend);
		btnSend.addSelectionListener(new SelectionListener<ButtonEvent>() {
			@Override
			public void componentSelected(ButtonEvent ce) {
				Title title = new Title(caption.getValue(), degree
						.getSimpleValue());
				Dispatcher.forwardEvent(AppEvents.SaveTitle, title);
				hide();

			}
		});

		FormButtonBinding binding = new FormButtonBinding(form);
		binding.addButton(btnSend);

		add(form);
	}
}
